﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EXOWorld.Presentation
{
    public partial class Admin_login : System.Web.UI.Page
    {
        private EXOWorld.Service.UserAccountService userAccountService;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnRetrieve_Click(object sender, EventArgs e)
        {

            Login login = userAccountService.getLoginInfo(txtUserID.Text);
            if (login != null)
            {
                txtUserID.Text = login.UID;
                txtUserName.Text = login.UserName;
                txtPassword.Text = login.Password;
                txtSecurityQue.Text = login.SecurityQuestion;
                txtSecurityQueAns.Text = login.Answer;
                txtRoomType.Text = login.Type;
                
            }
            else ClearFields();

                
            
        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {
            Login newLogin = new Login();

            newLogin.UID = "0000";          
            newLogin.UserName = txtUserName.Text;
            newLogin.Password = txtPassword.Text;
            newLogin.SecurityQuestion = txtSecurityQue.Text;
            newLogin.Answer = txtSecurityQueAns.Text;
            newLogin.Type = txtRoomType.Text;

            userAccountService.createNewLogin(newLogin);
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            Login tempLogin = userAccountService.getLoginInfo(txtUserID.Text);

            
            tempLogin.UID = txtUserID.Text; ;
            tempLogin.UserName = txtUserName.Text;
            tempLogin.Password = txtPassword.Text;
            tempLogin.SecurityQuestion = txtSecurityQue.Text;
            tempLogin.Answer = txtSecurityQueAns.Text;
            tempLogin.Type = txtRoomType.Text;

            userAccountService.updateLoginInfo(tempLogin);
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            userAccountService.deleteUserInfo(txtUserID.Text);
            ClearFields();
        }

        private void ClearFields()
        {
            txtUserID.Text = string.Empty;
            txtUserName.Text = string.Empty;
            txtRoomType.Text = string.Empty;
            txtPassword.Text = string.Empty;
            txtSecurityQueAns.Text = string.Empty;  
            txtSecurityQue.Text = string.Empty;
            
        }
    }
}